package com.ddwl.gate.controller;


import com.ddwl.common.annotation.Auth;
import com.ddwl.common.controller.BaseController;
import com.ddwl.gate.util.OssUtil;
import com.ddwl.schema.bo.gate.AliYunUploadBo;
import com.ddwl.schema.vo.base.RestVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author Fu Zhaohui
 */
@Api(tags = "OSS服务")
@RequestMapping("/oss")
@RestController
public class OssController extends BaseController {

    @Autowired
    private OssUtil ossUtil;

    @GetMapping("/token")
    @Auth(required = false)
    @ApiOperation("获取OSS STS Token")
    public RestVo<Map<String, String>> getStsToken() {
        return RestVo.ok(ossUtil.getSecurityToken());
    }

    @PostMapping("/base64Upload")
    @Auth(required = false)
    @ApiOperation("获取OSS STS Token")
    public RestVo<String> base64Upload(@RequestBody AliYunUploadBo uploadBo) {
        return RestVo.ok(ossUtil.base64UploadFileThenReturn(uploadBo.getBase64String(), uploadBo.getFileName()));
    }
}
